# -*- coding=utf-8 -*-
from django import forms
from django.contrib.auth.models import User
from .models import UserProfile, UserInfo

class LoginForm(forms.Form):
    """
    用户登录表单类
    """
    username = forms.CharField()
    password = forms.CharField(widget=forms.PasswordInput)

# 注册表单的数据要入数据库，所以继承的是 ModelForm，
# 登录表单不需要入库，继承的是Form
class RegistrationForm(forms.ModelForm):
    """
    用户注册表单类
    """
    password = forms.CharField(widget=forms.PasswordInput)
    password2 = forms.CharField(widget=forms.PasswordInput)

    class Meta:
        model = User
        # username和email跟模型类的表单字段是一样的，
        # 所以不用重复定义，直接用下面的写法即可
        fields = ('username', 'email')

    def clean_password2(self):
        cd = self.cleaned_data
        if cd['password'] != cd['password2']:
            raise forms.ValidationError('Password do not match.')
        return cd['password2']

class UserProfileForm(forms.ModelForm):
    class Meta:
        model = UserProfile
        fields = ('phone',)


class UserForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ('email', )

class UserInfoForm(forms.ModelForm):
    class Meta:
        model = UserInfo
        fields = ('company', 'profession', 'aboutme', 'photo')